﻿using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.Account;
using WindowsForms.AOnline.View.Dictionary;
//using System.Threading.Tasks;

namespace WindowsForms.AOnline.Presenter.Dictionary.FixedAssetCategory
{
    public class FixedAssetCategoryPresenter : Presenter<IFixedAssetCategoryView>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AccountPresenter" /> class.
        /// </summary>
        /// <param name="view">The view.</param>
        public FixedAssetCategoryPresenter(IFixedAssetCategoryView view)
            : base(view)
        {
        }

        /// <summary>
        /// Displays the specified employ identifier.
        /// </summary>
        /// <param name="fixedAssetCategoryId">The employ identifier.</param>
        public void Display(string fixedAssetCategoryId)
        {
            if (fixedAssetCategoryId == null) { View.FixedAssetCategoryId = 0; return; }
            var obj = Model.GetFixedAssetCategory(int.Parse(fixedAssetCategoryId));
            View.FixedAssetCategoryId = obj.FixedAssetCategoryId;
            View.ParentId = obj.ParentId;
            View.FixedAssetCategoryCode = obj.FixedAssetCategoryCode;
            View.FixedAssetCategoryName = obj.FixedAssetCategoryName;
            View.DepreciationRate = obj.DepreciationRate;
            View.LifeTime = obj.LifeTime;
            View.Grade = obj.Grade;
            View.IsParent = obj.IsParent;
            View.OrgPriceAccountCode = obj.OrgPriceAccountCode;
            View.DepreciationAccountCode = obj.DepreciationAccountCode;
            View.CapitalAccountCode = obj.CapitalAccountCode;
            View.IsActive = obj.IsActive;
            View.UnitId = obj.UnitId;

        }

        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns>System.Int32.</returns>
        public string Save()
        {
            var obj = new FixedAssetCategoryModel
            {
                FixedAssetCategoryId = View.FixedAssetCategoryId,
                ParentId = View.ParentId,
                FixedAssetCategoryCode = View.FixedAssetCategoryCode,
                FixedAssetCategoryName = View.FixedAssetCategoryName,
                DepreciationRate = View.DepreciationRate,
                LifeTime = View.LifeTime,
                Grade = View.Grade,
                IsParent = View.IsParent,
                OrgPriceAccountCode = View.OrgPriceAccountCode,
                DepreciationAccountCode = View.DepreciationAccountCode,
                CapitalAccountCode = View.CapitalAccountCode,
                IsActive = View.IsActive,
                UnitId = View.UnitId

            };
            return View.FixedAssetCategoryId == 0 ? Model.AddFixedAssetCategory(obj) : Model.UpdateFixedAssetCategory(obj);
        }

        /// <summary>
        /// Deletes the specified employ identifier.
        /// </summary>
        /// <param name="fixedAssetCategoryId">The employ identifier.</param>
        /// <returns>System.Int32.</returns>
        public string Delete(int fixedAssetCategoryId)
        {
            return Model.DeleteFixedAssetCategory(fixedAssetCategoryId);
        }
    }
}
